﻿using System;
using System.ComponentModel;
using Loki.Data;
using Loki.Utils;
using Luna.Data.Configuration;

namespace Luna.Model
{
    public class LunaReferenceEntity<TData> : LunaEntity<TData>, ILunaReferenceEntity, IEquatable<IReference>
        where TData : class, IDataEntity<Guid>, IReferenceData
    {
        public LunaReferenceEntity()
            : base()
        {
        }

        public LunaReferenceEntity(LunaReferenceEntity<TData> entity)
            : base(entity)
        {
            BeginInit();
            Google = entity.Google;
            GoogleLastUpdate = entity.GoogleLastUpdate;
            ZohoCRM = entity.ZohoCRM;
            ZohoCRMLastUpdate = entity.ZohoCRMLastUpdate;
            LastUpdate = entity.LastUpdate;
            EndInit(!IsChanged);
        }

        public LunaReferenceEntity(TData data)
            : base(data)
        {
        }

        #region LastUpdate

        private static PropertyChangedEventArgs argsLastUpdateChanged = ObservableHelper.CreateChangedArgs<LunaReferenceEntity<TData>>(x => x.LastUpdate);

        private static PropertyChangingEventArgs argsLastUpdateChanging = ObservableHelper.CreateChangingArgs<LunaReferenceEntity<TData>>(x => x.LastUpdate);

        public DateTime? LastUpdate
        {
            get
            {
                return Data.LastUpdate;
            }

            set
            {
                if (value != Data.LastUpdate)
                {
                    NotifyChanging(argsLastUpdateChanging);
                    Data.LastUpdate = value;
                    NotifyChangedAndDirty(argsLastUpdateChanged);
                }
            }
        }

        #endregion LastUpdate

        #region Google

        private static PropertyChangedEventArgs argsGoogleChanged = ObservableHelper.CreateChangedArgs<LunaReferenceEntity<TData>>(x => x.Google);

        private static PropertyChangingEventArgs argsGoogleChanging = ObservableHelper.CreateChangingArgs<LunaReferenceEntity<TData>>(x => x.Google);

        public string Google
        {
            get
            {
                return Data.Google;
            }

            set
            {
                if (value != Data.Google)
                {
                    NotifyChanging(argsGoogleChanging);
                    Data.Google = value;
                    NotifyChangedAndDirty(argsGoogleChanged);
                }
            }
        }

        #endregion Google

        #region GoogleLastUpdate

        private static PropertyChangedEventArgs argsGoogleLastUpdateChanged = ObservableHelper.CreateChangedArgs<LunaReferenceEntity<TData>>(x => x.GoogleLastUpdate);

        private static PropertyChangingEventArgs argsGoogleLastUpdateChanging = ObservableHelper.CreateChangingArgs<LunaReferenceEntity<TData>>(x => x.GoogleLastUpdate);

        public DateTime? GoogleLastUpdate
        {
            get
            {
                return Data.GoogleLastUpdate;
            }

            set
            {
                if (value != Data.GoogleLastUpdate)
                {
                    NotifyChanging(argsGoogleLastUpdateChanging);
                    Data.GoogleLastUpdate = value;
                    NotifyChangedAndDirty(argsGoogleLastUpdateChanged);
                }
            }
        }

        #endregion GoogleLastUpdate

        #region ZohoCRM

        private static PropertyChangedEventArgs argsZohoCRMChanged = ObservableHelper.CreateChangedArgs<LunaReferenceEntity<TData>>(x => x.ZohoCRM);

        private static PropertyChangingEventArgs argsZohoCRMChanging = ObservableHelper.CreateChangingArgs<LunaReferenceEntity<TData>>(x => x.ZohoCRM);

        public int? ZohoCRM
        {
            get
            {
                return Data.ZohoCRM;
            }

            set
            {
                if (value != Data.ZohoCRM)
                {
                    NotifyChanging(argsZohoCRMChanging);
                    Data.ZohoCRM = value;
                    NotifyChangedAndDirty(argsZohoCRMChanged);
                }
            }
        }

        #endregion ZohoCRM

        #region ZohoCRMLastUpdate

        private static PropertyChangedEventArgs argsZohoCRMLastUpdateChanged = ObservableHelper.CreateChangedArgs<LunaReferenceEntity<TData>>(x => x.ZohoCRMLastUpdate);

        private static PropertyChangingEventArgs argsZohoCRMLastUpdateChanging = ObservableHelper.CreateChangingArgs<LunaReferenceEntity<TData>>(x => x.ZohoCRMLastUpdate);

        public DateTime? ZohoCRMLastUpdate
        {
            get
            {
                return Data.ZohoCRMLastUpdate;
            }

            set
            {
                if (value != Data.ZohoCRMLastUpdate)
                {
                    NotifyChanging(argsZohoCRMLastUpdateChanging);
                    Data.ZohoCRMLastUpdate = value;
                    NotifyChangedAndDirty(argsZohoCRMLastUpdateChanged);
                }
            }
        }

        #endregion ZohoCRMLastUpdate

        public bool Equals(IReference other)
        {
            return other != null && other.ID == ID;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as IReference);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}